home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
12984
/
12984.xpi
/
chrome
/
VideoDownloaderToolbar.jar
/
content
/
preferences.js
< prev
next >
Wrap
Text File
|
2010-01-29
|
6KB
|
193 lines
if(!com) var com={};
if(!com.VidBar) com.VidBar={};
com.VidBar.Preferences = {
pref : Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService).getBranch("vidbar."),
getPref : function(name, type, def_value) {
var v = def_value;
try {
switch (type) {
case "bool" :
v = this.pref.getBoolPref(name);
break;
case "int" :
v = this.pref.getIntPref(name);
break;
case "text" :
v = this.pref.getCharPref(name);
break;
}
} catch (e) {
}
return v;
},
setPref : function(name, type, value) {
try {
switch (type) {
case "bool" :
v = this.pref.setBoolPref(name, value);
break;
case "int" :
v = this.pref.setIntPref(name, value);
break;
case "text" :
v = this.pref.setCharPref(name, value);
break;
}
} catch (e) {
}
},
setCheck : function(name, defaultValue) {
document.getElementById(name).checked = this.getPref(name, "bool", defaultValue);
},
setRadio : function(name, defaultValue) {
var value = this.getPref(name, "text", defaultValue);
var rg = document.getElementById(name);
for (var i in rg.childNodes) {
var r = rg.childNodes[i];
if (r.value == value) {
rg.selectedIndex = i;
break;
}
}
},
setText : function(name, type, defaultValue) {
var value = this.getPref(name, type, defaultValue);
document.getElementById(name).value = value;
},
onLoad : function() {
this.setCheck("show-file-size", false);
//this.setCheck("show-file-duration", false);
this.setCheck("show-in-context-menu", true);
this.setRadio("layout-type", "toolbar");
//this.setRadio("icon-pos", "toolbar");
this.setRadio("icon-style", "3D");
this.setText("max-downloads", "int", 0);
this.setText("min-file-size", "int", 100);
document.getElementById("download-location").value = com.VidBar.Pref.getDownloadDirectory().path;
this.setRadio("filename-type", "title");
//this.setText("inbox-url", "");
var exts = this.getPref("media-extensions", "text",
"flv|ram|mpg|mpeg|avi|rm|wmv|mov|asf|mp3|rar|movie|divx|rbs|mp4|mpeg4");
// dump(exts+"\n");
var extList = exts.split("|");
var extListBox = document.getElementById("media-extensions");
for (var i in extList) {
if (extList[i] && extList[i] != "")
extListBox.appendItem(extList[i], extList[i]);
}
},
updateCheckPref : function(name) {
var v = document.getElementById(name).checked;
this.setPref(name, "bool", v);
},
updateRadioPref : function(name) {
var rg = document.getElementById(name);
this.setPref(name, "text", rg.selectedItem.value);
},
updateTextPref : function(name, type) {
var v = document.getElementById(name).value;
this.setPref(name, type, v);
},
checkStorageLocation : function() {
var stDir = document.getElementById("download-location").value;
var stDirFile = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
try {
stDirFile.initWithPath(stDir);
} catch (e) {
alert("Failed to create directory " + stDir);
return false;
}
if (stDirFile.exists()) {
if (!stDirFile.isDirectory()) {
alert(stDir + " is not a directory");
return false;
}
} else {
var r = confirm(stDir + " does not exis.\r\nDo you want to create now?");
if (r == false)
return false;
try {
stDirFile
.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0775)
} catch (e) {
alert("Failed to create directory " + stDir);
return false;
}
}
return true;
},
doOk : function() {
if (!this.checkStorageLocation())
return false;
this.updateCheckPref("show-file-size");
//this.updateCheckPref("show-file-duration");
this.updateCheckPref("show-in-context-menu");
this.updateRadioPref("layout-type");
//this.updateRadioPref("icon-pos");
this.updateRadioPref("icon-style");
this.updateTextPref("max-downloads", "int");
this.updateTextPref("min-file-size", "int");
this.updateRadioPref("filename-type");
//this.updateTextPref("inbox-url", "text");
com.VidBar.Pref.setDownloadDirectory(document.getElementById("download-location").value);
var extListBox = document.getElementById("media-extensions");
var extList = [];
for (var i in extListBox.childNodes) {
if (extListBox.childNodes[i].value
&& extListBox.childNodes[i].value != "")
extList.push(extListBox.childNodes[i].value);
}
this.setPref("media-extensions", "text", extList.join("|"));
return true;
},
changeDownloadDir : function() {
var element = document.getElementById("download-location");
var nsIFilePicker = Components.interfaces.nsIFilePicker;
var fp = Components.classes["@mozilla.org/filepicker;1"]
.createInstance(nsIFilePicker);
fp.init(window, "Select Directory to Store Videos",
nsIFilePicker.modeGetFolder);
var res = null;
res = fp.show();
if (res == nsIFilePicker.returnOK) {
element.value = fp.file.path;
}
},
addExt : function() {
var elem = document.getElementById("new-file-ext");
var ext = elem.value;
var extListBox = document.getElementById("media-extensions");
extListBox.appendItem(ext, ext);
elem.value = "";
},
removeExt : function() {
var extListBox = document.getElementById("media-extensions");
if (extListBox.selectedIndex != -1) {
extListBox.removeItemAt(extListBox.selectedIndex);
}
}
};